﻿using Jink.Core.Converters.Annotations;
using Jink.Core.Json.Converters.Factories;
using Jink.Core.Json.Values;

namespace Jink.Core.Json.Converters.Custom
{
    [Converter]
    internal static class CustomConverters
    {
        [Converter(Weight = 0.9)]
        public static JsonValue ToJson(IJsonConvertible jc)
        {
            return jc.Serialize();
        }

        [Converter(Weight = 0.9)]
        public static T FromJson<T>(JsonValue json)
            where T : IJsonConvertible
        {
            var instance = JsonFactory.Create<T>();
            instance.Deserialize(json);
            return instance;
        }
    }
}
